const express=require('express');
const router= express.Router();

const User =require('../models/users');
const { Mongoose } = require('mongoose');

router.post('/myarbitrary/upload',function(req,res){
    console.log(req.body)

    // var obj = JSON.parse("'"+req.body+"'")
    res.send(JSON.stringify(req.body)+"收到报文")
    var loginuser=new User((req.body))

    loginuser.save()
})

router.get('/myarbitras',function(req,res){
    
  
    var reqid = req.query.用户.toString()
    
    
    const query = User.findOne({"name": reqid  }).sort({ field: 'asc', _id: -1 }); 

        query.where('questions.编辑好的主观题').exists().exec(function(err, userfound){
        if(err){
            console.log(err);
        }
        else{
            console.log(JSON.stringify(userfound.questions)) 
            console.log(userfound.uploadTime)
            res.send(JSON.stringify(userfound.questions))
        }
    }
    )
    
    // const query = User.find(); 
    //     query.setOptions({ lean : true });
    //     query.where('name').gte("郭旭").exec(function(questions,uploadTime){
    //         console.log(questions)
    //         console.log(uploadTime)
    //     });

 
      
      
            

})


module.exports=router